package com.liwenfeng.diancanspringboot.controller.admin;

import com.liwenfeng.diancanspringboot.common.result.Result;
import com.liwenfeng.diancanspringboot.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
@Api(tags = "店铺状态管理")
public class ShopController {
    @Autowired
    private ShopService shopService;

    // 设置营业状态
    @PutMapping("/{status}")
    @ApiOperation("设置营业状态")
    public Result<String> startOrStop(@PathVariable String status) {
        log.info("status: {}", Objects.equals(status, "1") ? "营业中" : "打烊中");
        String result = shopService.startOrStop(status);
        return Result.success(result);
    }

    // 获取营业状态
    @GetMapping("/status")
    @ApiOperation("获取营业状态")
    public Result<Integer> getStatus() {
        log.info("获取状态");
        Integer status = shopService.getStatus();
        return Result.success(status);
    }
}
